package com.util;

import java.io.InputStream;
import java.util.Properties;

public class JdbcUtil {
    // https://blog.csdn.net/qq_38570633/article/details/109264186
    // 这里用的是方法4.1，反射连接
    public static String driver;
    public static String url;
    public static String user;
    public static String password;

    // 居然还有这种写法，静态块
    static{
        try{
            // 1.新建属性集对象
            Properties properties = new Properties();
            // 2.通过反射，新建字符输入流，读取mysql.properties文件
            InputStream inputStream = JdbcUtil.class.getClassLoader().getResourceAsStream("mysql.properties");
            // 3.将输入流中读取到的属性加载到properties属性集对象中
            properties.load(inputStream);
            // 4.根据键获取对应的值
            driver = properties.getProperty("driver");
            url = properties.getProperty("url");
            user = properties.getProperty("user");
            password = properties.getProperty("password");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
